package com.leedcode;
/*
* 345. 反转字符串中的元音字母
* */
public class LeedCode345 {
    public static void main(String[] args) {
        String s = ".,";
        String res = reverseVowels(s);
        System.out.println(res);
    }
    public static String reverseVowels(String s) {
        /*
        * left = 0; right = s.length() - 1
        * 同时遍历数组，直到元音
        * 交换元素，并且移动
        * */
        int left = 0;
        int right = s.length() - 1;
        String vowel = "aeiouAEIOU";
        char[] chs = s.toCharArray();
        while(left < right){
            while(left < chs.length && vowel.indexOf(chs[left]) < 0){
                left++;
            }
            while(right >= 0 && vowel.indexOf(chs[right]) < 0){
                right--;
            }
            if(left < right){
                char temp = chs[left];
                chs[left] = chs[right];
                chs[right] = temp;
                left++;
                right--;
            }
        }
        return new String(chs);
    }
}
